package com.newidea.jiangong.component;

import com.newidea.jiangong.service.WeatherService;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;


/**
 * 访问天气北京海淀、北京朝阳、雄安的天气情况。API调用收费，建工掏钱一年2024年11月9日
 */
@Component
public class WeatherScheduled {

    private final WeatherService weatherService;

    public WeatherScheduled(WeatherService weatherService) {
        this.weatherService = weatherService;
    }

    /**
     * 每5分钟采集一次
     */
    @Scheduled(cron = "0 0/5 * * * *")
    @Transactional(rollbackFor = Exception.class)
    public void saveWeather() {
        weatherService.saveWeather();
    }
}
